#include "mrect.h"
#ifdef GUI_APPLICATION

#include "geometry/mpoint.h"
#include "geometry/msize.h"

bool MRect::isInclude(const MRect &other) const
{
	if( this->isValid() and other.isValid() )
		return x() <= other.x() and x()+width() >= other.x()+other.width() and
			y() <= other.y() and y()+height() >= other.y()+other.height();
	return false;
}

bool MRect::isBeIncluded(const MRect &other) const
{
	if( this->isValid() and other.isValid() )
		return x() >= other.x() and x()+width() <= other.x()+other.width() and
			y() >= other.y() and y()+height() <= other.y()+other.height();
	return false;
}

const MRect &MRect::operator=(const MRect &other)
{
	_point = other._point;
	_size = other._size;
	return *this;
}

bool MRect::operator&(const MRect &other) const
{
	if( this->isValid() and other.isValid() )
		return x() < other.x()+other.width() and x()+width() > other.x() and
			y() < other.y()+other.height() and y()+height() > other.y();
	return false;
}

/*-----------------------------------------------------------------------*/

bool MBorderRect::resize(int width, int height, int border_width)
{
	if( border_width < 0 )
		return false;
	if( rect.resize(width, height) )
	{
		this->border_width = border_width;
		return true;
	}
	return false;
}

bool MBorderRect::resize(const MSize &size, int border_width)
{
	if( border_width < 0 )
		return false;
	if( rect.resize(size) )
	{
		this->border_width = border_width;
		return true;
	}
	return false;
}

bool MBorderRect::setBorderWidth(int border_width)
{
	if( border_width < 0 )
		return false;
	this->border_width = border_width;
	return true;
}

const MBorderRect &MBorderRect::operator=(const MBorderRect &other)
{
	rect = other.rect;
	border_width = other.border_width;
	return *this;
}


#endif //GUI_APPLICATION
